// 资源索引的目录
var ORIGIN = 'https://634174214.gitee.io/lib-wubin-work/';
// 部署在服务器上的目录
var SERVER_URL = window.location.href.indexOf('wubin.work') > -1 ? 'http://lib.wubin.work/' : 'http://lib.wubin.com/'
var $copyItem = $('.copy-item');
var $allH2 = $('h2');
var h2Idpre = 'h2-';
var fixedMenuIn = '';

$copyItem.each(function(index, item) {
    var path = $(item).data('path');
    var em = $(item).data('em');
    var emStr = em ? '<em>' + em + '</em>' : '';
    $(item).html(ORIGIN + path + emStr);
});

$allH2.each(function(index, item) {
    var id = h2Idpre + index;
    var text = $(item).text();
    $(item).attr('id', id);
    fixedMenuIn += '<a href="#' + id + '" title="' + text + '">' + text + '</a>';
    if (index == $allH2.length - 1) {
        var fixedMenuStr = '<div class="fixed-menu"><p>快速导航</p>' + fixedMenuIn + '</div>';
        $('body').append($(fixedMenuStr));
        scrollMark();
    }
});


$('.local-link-item').each(function() {
    var href = $(this).attr('href');
    var newHref = SERVER_URL + pagePath + href;
    $(this).attr('href', newHref);
});


function scrollMark() {
    $('.fixed-menu').on('click', 'a', function(e) {
        e.preventDefault();
        var h2 = $(this).attr('href');
        $('html, body').animate({
            scrollTop: $(h2).position().top
        }, 'slow');
    });
}





